/*
 * @Descripttion: 
 * @version: 
 * @Author: 玄绮 <shijiahansi@qq.com>
 * @Date: 2021-11-07 17:36:10
 * @LastEditTime: 2021-11-08 09:22:29
 * @LastEditors: VS Code
 */

#include "tetris.h"

uint8 gled_col_page[] = {0x08, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x08};

// ,
// {0x00, 0xe0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00},
// {0x40, 0x30, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00}

uint8 gled_col_1[][3] = {{0x00, 0x40, 0xe0},
                         {0x40, 0xc0, 0x40},
                         {0x00, 0xe0, 0x40},
                         {0x40, 0x60, 0x40}};

uint8 *leddz_add_block(uint8 *col_buf, const tetris_block_t *block)
{
    uint8 i, j;
    for (i = 0; i < 3; i++)
    {
        j = i + block->p_row;
        if (j < 8)
            col_buf[j] |= (block->col[block->index][i] >> block->p_col);
    }
    return col_buf;
}

uint8 *leddz_copy_col(uint8 *col_buf, const uint8 *col)
{
    uint8 i;
    for (i = 0; i < 8; i++)
        col_buf[i] = col[i];
    return col_buf;
}

// uint8 *leddz_add_col(uint8 *col_buf, const uint8 *col)
// {
//     uint8 i, j;
//     for (i = 0; i < 8; i++)
//         col_buf[j] |= col[j];
//     return col_buf;
// }

void leddz_outImg_col_test(tetris_block_t *block2)
{
    uint8 i = 0, j = 0;
    uint8 col_buf[8] = {0};
    tetris_block_t block1;
    block1.col = gled_col_1;
    block1.index = 0;
    block1.p_col = 5;
    block1.p_row = 0;
    if (block2)
        i = 0;

    P2 = ~0;

    leddz_copy_col(col_buf, gled_col_page);
    leddz_add_block(col_buf, &block1);
    leddz_add_block(col_buf, block2);

    for (i = 0; i < 8; i++) //循环8次扫描8行、列
    {
        hc595_write_data(0x80 >> i);
        LEDDZ_COL_PORT = ~col_buf[i];
        delay_10us(25);         //延时一段时间，等待显示稳定
        hc595_write_data(0x00); //消影
    }
}